$('#btnAdd').click(function () {
    $.ajax({
        url: '/student/add',
        method: 'post',
        data: $('#frmInput').serialize()
    }).then(res => {
        if (res.msg === 'OK') {
            alert('添加数据成功！');
        } else {
            alert('添加数据失败！')
        }
        window.location.href = '/student';
    });
});

//删除指定学号的学生信息
function del(sNo){
    $.ajax({
        url: '/student/del',
        method: 'post',
        data: 'sNo=' + sNo
    }).then(res => {
        if (res.msg === 'OK') {
            alert('删除数据成功！');
        } else {
            alert('删除数据失败！')
        }
        window.location.href = '/student';
    });
}

//修改指定学号的学生信息
function modify(stu){

    $('div.mask').show();

    $('input[name=sNo]').val(stu.sNo);
    $('input[name=sName]').val(stu.sName);
    $('input[name=sBirthday]').val(stu.sBirthday.substr(0,10));
    $('select[name=class]').val(stu.class);
    var radios = $('input[name=sSex]');
    for(var radio of radios){
        radio.checked = (radio.value === stu.sSex);
    }
}